productManagementProto = {
   productEditorStore : null
   ,initComponent: function(){
       this.productEditor = Ext.create(this.editorDefinitions);
       this.items = [this.productEditor];

       productManagement.superclass.initComponent.call(this);
 
       sweatShop.globals.bindHandlers(this.id, this.getHandlers());
       this.productEditorStore = this.productEditor.getStore();
       this.productEditorStore.on('write', globals.proxyResultListener);
       this.productEditorStore.on('delete', globals.proxyResultListener);
       
       this.reloadGrid();
   }
   , getHandlers : function()
    {
        return {
          deleteProductButton : {fn: this.onDelete, scope: this.productEditor}
          ,addProductButton : {fn: this.addNewProduct, scope: this.productEditor}
          ,reloadProductsButton : {fn : this.reloadGrid, scope:this}
        };
    }
    , reloadGrid : function ()
    {
        this.productEditorStore.reload();
    }
    , onSave : function(btn, ev) {
        this.store.save();
    }
    , onDelete : function (btn, ev)
    {
        var index = this.getSelectionModel().getSelectedCell();
        if (!index) {
            return false;
        }
        var rec = this.store.getAt(index[0]);
       this.store.remove(rec);
    }
    , addNewProduct : function()
    {
        console.log('Adding new product...');
        var newProduct = this.getStore().recordType;
        this.stopEditing();
        this.getStore().insert(0, new newProduct({
            productId: null,
            product: ''
        }));
        this.startEditing(0, 1);
    }
};
productManagement = Ext.extend(productManagementUi, productManagementProto);
